//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2002-2004
//
// COM port stuff.
//

# include "StdAfx.h"
# include "ComPort.h"

CComPort::CComPort (const char * _strPort, DWORD _dwAccess) :
	CFile (_strPort, _dwAccess, 0, OPEN_EXISTING, 0)//FILE_ATTRIBUTE_NORMAL)
{}

void CComPort::ClearQueues () {
	::PurgeComm (m_h, PURGE_TXCLEAR | PURGE_RXCLEAR);
}

void CComPort::SetDCB (DWORD _dwBaudRate, BYTE _btByteSize, bool _bParity, BYTE _btStopBits) {
	assert (IsValid ());

	DCB dcb = {sizeof (DCB)};
	::GetCommState (m_h, & dcb);
	dcb.BaudRate = _dwBaudRate;
	dcb.ByteSize = _btByteSize;
	dcb.fParity = _bParity ? 1 : 0;
	dcb.StopBits = _btStopBits;
	::SetCommState (m_h, & dcb);
}

size_t CComPort::GetInQueueSize () const {
	assert (IsValid ());

	COMSTAT cs;
	cs.cbInQue = 0;
	DWORD dwErrorCode = 0;
	::ClearCommError (m_h, & dwErrorCode, & cs);
	return cs.cbInQue;
}